﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class FieldSpecDetailBLL : IFieldSpecDetailBLL
    {
        private static readonly IFieldSpecDetailDAL DAL = DataAccess.CreateFieldSpecDetails();
        private static readonly IFieldSpecificationDAL specDAL = DataAccess.CreateFieldSpecifications();
        private static readonly IPositionTypeDAL ptDAL = DataAccess.CreatePositionTypes();
        private static readonly IClassDAL clDAL = DataAccess.CreateClasses();

        private FieldSpecificationInfo specInfo = new FieldSpecificationInfo();
        private PositionTypeInfo ptInfo = new PositionTypeInfo();
        private ClassInfo clInfo = new ClassInfo();

        public IList<FieldSpecDetailInfo> ListFieldSpecDetails()
        {
            return DAL.ListFieldSpecDetails(new FieldSpecDetailInfo(0));
        }
        public IList<FieldSpecDetailInfo> ListFieldSpecDetailsBySequence(string Sequence)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return DAL.ListFieldSpecDetails(new FieldSpecDetailInfo(Seq));
        }
        public IList<FieldSpecDetailInfo> ListFieldSpecDetailsByFielsSpec(string FieldSpecSeq)
        {
            specInfo.Sequence = FieldSpecSeq.Length > 0 ? Int32.Parse(FieldSpecSeq) : 0;
            return DAL.ListFieldSpecDetails(new FieldSpecDetailInfo(0, specInfo, ptInfo, clInfo, 0, "", "", null, null));
        }
        public void Insert(string FieldSpecSeq, string PositionTypes, string Classes, string Durations, string Remarks, int CreatedBy)
        {
            try
            {
                specInfo.Sequence = FieldSpecSeq.Length > 0 ? Int32.Parse(FieldSpecSeq) : 0;
                ptInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
                clInfo.Sequence = Classes.Length > 0 ? Int32.Parse(Classes) : 0;
                double duration = Durations.Length > 0 ? Double.Parse(Durations) : 0;
                DAL.Insert(new FieldSpecDetailInfo(0, specInfo, ptInfo, clInfo, duration, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string FieldSpecSeq, string PositionTypes, string Classes, string Durations, string Remarks, int UpdatedBy)
        {
            try
            {
                specInfo.Sequence = FieldSpecSeq.Length > 0 ? Int32.Parse(FieldSpecSeq) : 0;
                ptInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
                clInfo.Sequence = Classes.Length > 0 ? Int32.Parse(Classes) : 0;
                double duration = Durations.Length > 0 ? Double.Parse(Durations) : 0;
                DAL.Update(new FieldSpecDetailInfo(Sequence, specInfo, ptInfo, clInfo, duration, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
